package org.rsbot.script.wrappers;

import java.awt.Point;
import java.lang.ref.SoftReference;
import org.rsbot.client.RSPlayerComposite;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Menu;
import org.rsbot.script.methods.MethodContext;
import org.rsbot.script.methods.Mouse;

public class RSPlayer extends RSCharacter
{
  private SoftReference<org.rsbot.client.RSPlayer> p;

  public RSPlayer(MethodContext paramMethodContext, org.rsbot.client.RSPlayer paramRSPlayer)
  {
    super(paramMethodContext);
    this.p = new SoftReference(paramRSPlayer);
  }

  protected org.rsbot.client.RSCharacter getAccessor() {
    return (org.rsbot.client.RSCharacter)this.p.get();
  }

  public int getCombatLevel() {
    return ((org.rsbot.client.RSPlayer)this.p.get()).getLevel();
  }

  public String getName()
  {
    return ((org.rsbot.client.RSPlayer)this.p.get()).getName();
  }

  public int getTeam() {
    return ((org.rsbot.client.RSPlayer)this.p.get()).getTeam();
  }

  public int getNPCID() {
    RSPlayerComposite localRSPlayerComposite = ((org.rsbot.client.RSPlayer)this.p.get()).getComposite();
    if (localRSPlayerComposite != null) {
      return localRSPlayerComposite.getNPCID();
    }
    return -1;
  }

  public boolean isIdle() {
    return (!isMoving()) && (getAnimation() == -1) && (!isInCombat());
  }

  public boolean doAction(String paramString)
  {
    try
    {
      for (int i = 0; i < 20; i++) {
        Point localPoint = getScreenLocation();
        if ((!isValid()) || (!this.methods.calc.pointOnScreen(localPoint))) {
          return false;
        }
        if (this.methods.mouse.getLocation().equals(localPoint)) {
          break;
        }
        this.methods.mouse.move(localPoint);
      }
      String[] arrayOfString = this.methods.menu.getItems();
      if (arrayOfString.length <= 1)
        return false;
      if (arrayOfString[0].toLowerCase().contains(paramString.toLowerCase())) {
        this.methods.mouse.click(true);
        return true;
      }
      this.methods.mouse.click(false);
      return this.methods.menu.doAction(paramString);
    }
    catch (Exception localException) {
      localException.printStackTrace();
    }return false;
  }

  public String toString()
  {
    return "Player[" + getName() + "]" + super.toString();
  }
}